package com.itheima.ydd.controller;


import com.itheima.ydd.common.R;
import com.itheima.ydd.common.ResultData;
import com.itheima.ydd.entity.YddAdvimg;
import com.itheima.ydd.entity.YddAdvpos;
import com.itheima.ydd.service.IYddAdvimgService;
import com.itheima.ydd.service.IYddAdvposService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2022-05-22
 */
@RestController
@RequestMapping("/ydd_advimg")
public class YddAdvimgController {
    @Autowired
    private IYddAdvimgService yddAdvimgService;

    @GetMapping("/list")
    public ResultData selectByPage(String advimgdesc,String advimgpos, Integer page, Integer limit){
        ResultData selectByPage = yddAdvimgService.selectByPage(advimgdesc,advimgpos,page,limit);
        return selectByPage;
    }

    @PostMapping("/add")
    public R add(@RequestBody YddAdvimg yddAdvimg){

        String[] split = yddAdvimg.getAdvimgsrc().split("/");
        yddAdvimg.setAdvimgsrc("/"+split[1]);

        yddAdvimgService.add(yddAdvimg);
        return R.success("200",null);
    }

    @GetMapping("/all")
    public ResultData selectall(){
        ResultData selectByall = yddAdvimgService.selectByselectByall();
        return selectByall;
    }
     //数据回显
    @GetMapping("/rowInfo")
    public ResultData rowInfo(Integer id){
        ResultData selectByall = yddAdvimgService.rowInfo(id);
        return selectByall;
    }
    //修改
    @PostMapping("/update")
    public R update(@RequestBody YddAdvimg yddAdvimg){
        String[] split = yddAdvimg.getAdvimgsrc().split("/");
        yddAdvimg.setAdvimgsrc("/"+split[1]);
        yddAdvimgService.updateyddArt(yddAdvimg);
        return R.success("200",null);
    }

    //根据id删除
    @GetMapping("/del")
    public R deleteById(Integer id){
        yddAdvimgService.deleteById(id);
        return R.success("200",null);
    }
}
